<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\Admin;
/*
 * -- ----------------------------
 * --  后台登录
 * -- ----------------------------
 */
class Login extends Controller
{
  /**
   * 管理员登录
   */
  public function index(){
    $admin = new Admin();
    if(request()->isAjax()){
      $num = $admin->login(input('post.'));
      $data = $this->check_verify(input('code'));
      if(!$data){
        $back = [
          'statu' => 400,
          'info' => '验证码错误'
        ];
        return $back;
      }
      if($num == 1){
        $back = [
          'statu' => 400,
          'info' => '用户不存在'
        ];
        return $back;
      }
      if($num == 2){
        $back = [
          'statu' => 200,
          'info' => '登录成功'
        ];
        return $back;
        // $this->success('登录成功','Index/index');
      }
      if($num == 3){
        $back = [
          'statu' => 400,
          'info' => '密码错误'
        ];
        return $back;
      }
      return;
    }
    return view();
  }

  /**
   * 验证码验证
   */
  function check_verify($code=''){
    $captcha = new \think\captcha\Captcha();
    if (!$captcha->check($code)) {
      return false;
    }else{
      return true;
    }
  }
  
  /**
   * 空操作
   */
  public function _empty(){
    $this->redirect('login/index');
  }
}
?>